package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TBaseFile;
import com.ruoyi.system.service.ITBaseFileService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目文件Controller
 * 
 * @author ruoyi
 * @date 2024-03-22
 */
@RestController
@RequestMapping("/system/file")
public class TBaseFileController extends BaseController
{
    @Autowired
    private ITBaseFileService tBaseFileService;

    /**
     * 查询项目文件列表
     */
//    @PreAuthorize("@ss.hasPermi('system:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(TBaseFile tBaseFile)
    {
        startPage();
        List<TBaseFile> list = tBaseFileService.selectTBaseFileList(tBaseFile);
        return getDataTable(list);
    }

    /**
     * 导出项目文件列表
     */
//    @PreAuthorize("@ss.hasPermi('system:file:export')")
    @Log(title = "项目文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TBaseFile tBaseFile)
    {
        List<TBaseFile> list = tBaseFileService.selectTBaseFileList(tBaseFile);
        ExcelUtil<TBaseFile> util = new ExcelUtil<TBaseFile>(TBaseFile.class);
        util.exportExcel(response, list, "项目文件数据");
    }

    /**
     * 获取项目文件详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:file:query')")
    @GetMapping(value = "/{fileId}")
    public AjaxResult getInfo(@PathVariable("fileId") Integer fileId)
    {
        return success(tBaseFileService.selectTBaseFileByFileId(fileId));
    }

    /**
     * 新增项目文件
     */
//    @PreAuthorize("@ss.hasPermi('system:file:add')")
    @Log(title = "项目文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TBaseFile tBaseFile)
    {
        tBaseFile.setCreateDate(DateUtils.getNowDate());
        tBaseFile.setCreatePerson(SecurityUtils.getUserId().toString());
        return toAjax(tBaseFileService.insertTBaseFile(tBaseFile));
    }

    /**
     * 修改项目文件
     */
//    @PreAuthorize("@ss.hasPermi('system:file:edit')")
    @Log(title = "项目文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TBaseFile tBaseFile)
    {
        tBaseFile.setUpdateDate(DateUtils.getNowDate());
        tBaseFile.setUpdatePerson(SecurityUtils.getUserId().toString());
        return toAjax(tBaseFileService.updateTBaseFile(tBaseFile));
    }

    /**
     * 删除项目文件
     */
//    @PreAuthorize("@ss.hasPermi('system:file:remove')")
    @Log(title = "项目文件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fileIds}")
    public AjaxResult remove(@PathVariable Integer[] fileIds)
    {
        return toAjax(tBaseFileService.deleteTBaseFileByFileIds(fileIds));
    }
}
